package work4

import (
	"errors"
	"time"
)

const TIME_LAYOUT = "2006-01-02 15:04:05"

func GetTime(startTime, endTime string) (error, float64) {

	//将当前时间进行转换成 UTC时间
	var err error
	loc, _ := time.LoadLocation("America/New_York")
	start, err := time.ParseInLocation(TIME_LAYOUT, startTime, loc)
	if err != nil {
		return errors.New("转换时间失败1"), 0
	}
	end, err := time.ParseInLocation(TIME_LAYOUT, endTime, loc)
	if err != nil {
		return errors.New("转换时间失败2"), 0
	}
	//计算两个时间差
	second := int(end.Unix() - start.Unix())
	if end.IsDST() && start.IsDST() && second < 0 {
		second += 3600
	}

	if second > 3000 || second < 0 {
		return errors.New("通话时间不正确"), 0
	}
	//秒时间转换成分钟
	var minute int
	if second%60 == 0 {
		minute = second / 60
	} else {
		minute = (second + 59) / 60
	}
	//计算金额
	var money float64 = 0
	if minute <= 20 {
		money = float64(minute) * 0.05
	} else {
		money += 1
		money += float64(minute-20) * 0.1
	}
	return nil, money
}
